<template>
  <div>
    <el-container>
      <el-header>
        <el-row>
          <el-col :span="2">
            <div class="grid-content bg-purple">
              <img
                src="https://escook.cn/vue-shop/img/heima.b5a855ee.png"
                alt=""
              />
            </div>
          </el-col>
          <el-col :span="19">
            <div class="grid-content bg-purple-light">
              <h1>电商后台管理系统</h1>
            </div>
          </el-col>
          <el-col :span="1">
            <div class="grid-content bg-purple">
              <el-button type="info" @click="LoginOut">退出</el-button>
            </div>
          </el-col>
        </el-row>
      </el-header>
      <el-container>
        <el-aside :width="Iscollapse == false ? '200px ' : '64px'">
          <!-- <pre> {{$route.path.replace('/','')}}</pre> -->

          <el-menu
            :default-active="$route.path.replace('/', '')"
            class="el-menu-vertical-demo"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b"
            :unique-opened="true"
            :collapse-transition="false"
            router
            mode="vertical"
            :collapse="Iscollapse"
          >
            <i class="el-icon-s-operation" @click="Rio"></i>
            <el-submenu
              :index="item.id + ''"
              v-for="(item,index) in menus"
              :key="item.id"
            >
              <template slot="title">
                <svg class="icon" aria-hidden="true">
                  <use :xlink:href='arr[index]'>
                    <!-- #icon- -->
                  </use>
                </svg>
                <span>{{ item.authName }}</span>
              </template>

              <el-menu-item
                :index="item1.path"
                v-for="item1 in item.children"
                :key="item1.id"
              >
                <i class="el-icon-setting"></i>
                <span slot="title">{{ item1.authName }}</span>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  components: {},
  data() {
    return {
      menus: [],
      Iscollapse: false,
      arr:{
        0:'#icon-jurassic_user',
        1:'#icon-quanxian',
        2:'#icon-shangpin',
        3:'#icon-dingdan',
        4:'#icon-shuju01',
      }
    }
  },
  created() {
    // 获取数据
    this.getlist()
  },
  mounted() {},
  methods: {
    // 获取左侧菜单
    async getlist() {
      const res = await this.$http.Menus()
      this.menus = res
      console.log(res)
    },
    // 退出登录
    LoginOut() {
      this.$confirm('此操作将永久退出登录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.$router.go(-1)
          sessionStorage.removeItem('token')
          this.$message({
            type: 'success',
            message: '退出成功!'
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消退出'
          })
        })
    },
    Rio() {
      this.Iscollapse = !this.Iscollapse
    }
  }
}
</script>
<style >
.el-submenu .el-menu-item {
  min-width: 0px;
}
</style>
<style scoped lang='scss'>
.el-header,
.el-footer {
  background-color: #373d41;
  color: #fff;
  // text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  height: 92vh;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  // text-align: center;
}
::v-depp.el-menu-item {
  min-width: 0px;
}
</style>
